<template>
	<view style="height: 100%;">
		<cu-custom :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">{{navTitle}}</block>
		</cu-custom>
		<view class="container">
			<view class="tui-cells">
				<textarea @input="contentInput" class="tui-textarea" name="desc" :placeholder="placeholder" maxlength="500"
					placeholder-class="tui-phcolor-color" auto-focus />
				<view class="tui-textarea-counter">{{content.length}}/500</view>
			</view>
			<view style="height: 50upx;"></view>
			<view class="flex justify-center">
				<button @tap="commitAction" :class="'cu-btn round '+themeColor" style="width: 70%;">发表</button>
			</view>
		</view>
	</view>
</template>

<script>
	import {sendAdvice} from '@/api/api.js'
	export default {
		data() {
			return {
				themeColor:this.ThemeColor,
				isRecommendMini:false,
				isRecommendOfficial:false,
				content:'',
			};
		},
		computed: {
			navTitle() {
				if(this.isRecommendMini) {
					return '推荐小程序'
				}
				if(this.isRecommendOfficial) {
					return '推荐公众号'
				}
				return '投诉与建议'
			},
			placeholder() {
				if(this.isRecommendMini) {
					return '请输入小程序名称和简要的推荐语'
				}
				if(this.isRecommendOfficial) {
					return '请输入公众号名称和简要的推荐语'
				}
				return '投诉与建议'
			},
		},
		onLoad(options) {
			if(options.isRecommend !== null && options.isRecommend !== undefined && options.isRecommend !== "") 
			{
				if(options.isRecommend == 1) {
					this.isRecommendMini = true
				}
				if(options.isRecommend == 2) {
					this.isRecommendOfficial = true
				}
			}
		},
		methods: {
			commitAction() 
			{
				if(this.content.length == 0) {
					return
				}
				uni.showLoading({
					title:'正在提交...'
				})
				sendAdvice(this.content).then(res=>{
					uni.hideLoading()
					uni.showToast({
						title:'提交成功，感谢反馈!'
					})
					this.content = ''
				}).catch(error=>{
					uni.hideLoading()
				})
			},
			contentInput(e) 
			{
				this.content = e.detail.value
			}
		}
	};
</script>

<style>
	page {
		background: #fff;
		color: #333;
	}

	.container {
		padding: 30rpx;
		box-sizing: border-box;
	}

	.tui-cells {
		border-radius: 4rpx;
		height: 280rpx;
		box-sizing: border-box;
		padding: 20rpx 20rpx 0 20rpx;
		position: relative;
	}

	.tui-cells::after {
		content: '';
		position: absolute;
		height: 200%;
		width: 200%;
		border: 1px solid #e6e6e6;
		transform-origin: 0 0;
		-webkit-transform-origin: 0 0;
		-webkit-transform: scale(0.5);
		transform: scale(0.5);
		left: 0;
		top: 0;
		border-radius: 8rpx;
		pointer-events: none;
	}

	.tui-textarea {
		height: 210rpx;
		width: 100%;
		color: #666;
		font-size: 28rpx;
	}

	.tui-phcolor-color {
		color: #ccc !important;
	}

	.tui-textarea-counter {
		font-size: 24rpx;
		color: #999;
		text-align: right;
		height: 40rpx;
		line-height: 40rpx;
		padding-top: 4rpx;
	}

	.tui-enclosure {
		display: flex;
		align-items: center;
		padding: 26rpx 10rpx;
		box-sizing: border-box;
	}

	.tui-cmt-btn {
		margin-top: 60rpx;
	}
</style>
